package com.yanqu.road.logic.bussiness.player;

import com.yanqu.road.entity.player.*;
import com.yanqu.road.logic.bussiness.DaoHelper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UserVehicleBussiness {

	public static Map<String, UserVehicle> getUserVehicleMap(long userId) {
		return DaoHelper.getUserVehicleDaoImpl().getUserVehicleMap(userId);
	}

	public static Map<Long,Map<String, UserVehicle>> getSomeUserVehicleMap(List<Long> userIdList) {
		return DaoHelper.getUserVehicleDaoImpl().getSomeUserVehicleMap(userIdList);
	}

	public static boolean addUserVehicle(UserVehicle userVehicle) {
		return DaoHelper.getUserVehicleDaoImpl().add(userVehicle);
	}

	public static boolean updateUserVehicle(UserVehicle userVehicle) {
		return DaoHelper.getUserVehicleDaoImpl().update(userVehicle);
	}

	public static Map<String, Map<Integer, UserVehicleSkill>> getUserVehicleSkillMap(long userId) {
		return DaoHelper.getUserVehicleSkillDaoImpl().getUserVehicleSkillMap(userId);
	}

	public static Map<Integer, UserVehicleSkill> getUserVehicleSkillMap(long userId, String vehicleUid) {
		return DaoHelper.getUserVehicleSkillDaoImpl().getUserVehicleSkillMap(userId, vehicleUid);
	}

	public static boolean addUserVehicleSkill(UserVehicleSkill userVehicleSkill) {
		return DaoHelper.getUserVehicleSkillDaoImpl().add(userVehicleSkill);
	}

	public static boolean updateUserVehicleSkill(UserVehicleSkill userVehicleSkill) {
		return DaoHelper.getUserVehicleSkillDaoImpl().update(userVehicleSkill);
	}

	public static Map<String, List<UserVehicleOtherSkill>> getUserVehicleOtherSkillList(long userId) {
		return DaoHelper.getUserVehicleOtherSkillDaoImpl().getUserVehicleOtherSkillList(userId);
	}

	public static List<UserVehicleOtherSkill> getUserVehicleOtherSkillList(long userId, String vehicleUid) {
		return DaoHelper.getUserVehicleOtherSkillDaoImpl().getUserVehicleOtherSkillList(userId, vehicleUid);
	}

	public static boolean addUserVehicleOtherSkill(UserVehicleOtherSkill userVehicleOtherSkill) {
		return DaoHelper.getUserVehicleOtherSkillDaoImpl().add(userVehicleOtherSkill);
	}

	public static boolean updateUserVehicleOtherSkill(UserVehicleOtherSkill userVehicleOtherSkill) {
		return DaoHelper.getUserVehicleOtherSkillDaoImpl().update(userVehicleOtherSkill);
	}

	public static Map<String, UserVehicle> getUserVehicleAndSkillMap(long userId, int patronsId) {
		Map<String, UserVehicle> userVehicleMap = getUserVehicleMap(userId);
		Map<String, UserVehicle> resultMap = new HashMap<>();

		UserVehicle userVehicle = null;
		for (Map.Entry<String, UserVehicle> entry : userVehicleMap.entrySet()) {
			if(entry.getValue().getPatronsId() == patronsId){
				userVehicle = entry.getValue();
				break;
			}
		}
		if(userVehicle == null){
			return resultMap;
		}
		Map<Integer, UserVehicleSkill> skillMap = getUserVehicleSkillMap(userId, userVehicle.getVehicleUid());
		userVehicle.setSkillMap(skillMap);

		List<UserVehicleOtherSkill> otherSkillList = getUserVehicleOtherSkillList(userId, userVehicle.getVehicleUid());
		userVehicle.setOtherSkillList(otherSkillList);

		resultMap.put(userVehicle.getVehicleUid(), userVehicle);
		return resultMap;
	}

	public static Map<String, UserVehicle> getUserVehicleAndSkillMap(long userId) {
		Map<String, UserVehicle> userVehicleMap = getUserVehicleMap(userId);
		Map<String, Map<Integer, UserVehicleSkill>> skillMap = getUserVehicleSkillMap(userId);
		//装备技能信息
		for (Map.Entry<String, Map<Integer, UserVehicleSkill>> skillEntry : skillMap.entrySet()) {
			if (userVehicleMap.containsKey(skillEntry.getKey())) {
				userVehicleMap.get(skillEntry.getKey()).setSkillMap(skillEntry.getValue());
			}
		}
		//組合珍兽的新技能光环
		Map<String, List<UserVehicleOtherSkill>> otherSkillList = getUserVehicleOtherSkillList(userId);
		for (Map.Entry<String, List<UserVehicleOtherSkill>> skillEntry : otherSkillList.entrySet()) {
			if (userVehicleMap.containsKey(skillEntry.getKey())) {
				userVehicleMap.get(skillEntry.getKey()).setOtherSkillList(skillEntry.getValue());
			}
		}

		return userVehicleMap;
	}

	public static UserVehicleDetail getUserVehicleDetail(long userId) {
		return DaoHelper.getUserVehicleDetailDaoImpl().getUserVehicleDetail(userId);
	}

	public static boolean addUserVehicleDetail(UserVehicleDetail userVehicleDetail) {
		return DaoHelper.getUserVehicleDetailDaoImpl().add(userVehicleDetail);
	}

	public static boolean updateUserVehicleDetail(UserVehicleDetail userVehicleDetail) {
		return DaoHelper.getUserVehicleDetailDaoImpl().update(userVehicleDetail);
	}

	public static Map<String, PatronsVehicleBindingData> getPatronsVehicleBindingData(long userId){
		return DaoHelper.getPatronsVehicleBindingDaoImpl().getPatronsVehicleBindingData(userId);
	}

	public static boolean addPatronsVehicleBindingData(PatronsVehicleBindingData data){
		return DaoHelper.getPatronsVehicleBindingDaoImpl().add(data);
	}

	public static boolean aupdatePatronsVehicleBindingData(PatronsVehicleBindingData data){
		return DaoHelper.getPatronsVehicleBindingDaoImpl().update(data);
	}

}
